// configureStore: 用于创建、配置store对象方法
import { configureStore } from "@reduxjs/toolkit";
import type { Action, ThunkAction } from "@reduxjs/toolkit";
// import { setupListeners } from "@reduxjs/toolkit/query";
import { rootReducer } from "./combineReducer";

export type RootState = ReturnType<typeof rootReducer>;

export const makeStore = (preloadedState?: Partial<RootState>) => {
  const store = configureStore({
    // 是否开启浏览器的 redux 开发调试工具
    devTools: process.env.NODE_ENV !== "production",
    reducer: rootReducer,
    // reducer: {},
    // and other useful features of `rtk-query`.
    // middleware: (getDefaultMiddleware) => {
    //   return getDefaultMiddleware().concat(quotesApiSlice.middleware);
    // },
    preloadedState,
  });
  // setupListeners(store.dispatch);
  return store;
};
export const store = makeStore();
export type AppStore = typeof store;
export type AppDispatch = AppStore["dispatch"];

// export type AppDispatch = typeof store.dispatch;
export type AppThunk<ThunkReturnType = void> = ThunkAction<
  ThunkReturnType,
  RootState,
  unknown,
  Action<string>
>;
